package com.sxf.biz.operator.controller;

import com.sxf.auth.login.vo.*;
import com.sxf.biz.customer.vo.*;
import com.sxf.biz.operator.service.OpService;
import com.sxf.biz.operator.vo.*;
import com.sxf.common.param.BaseVO;
import com.sxf.common.param.PageBaseVO;
import com.sxf.common.param.ResultInfo;
import com.sxf.core.db.page.Pagination;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @description: TODO
 * @Author Leo
 * @date 2024/3/1820:26
 */
@RestController
@Api(value = "运营端相关", tags = { "运营端相关" })
@Validated
@RequestMapping("/op")
public class OperatorController {

    @Autowired
    OpService opService;

    @ApiOperation(value = "运营首页数据统计", produces = "application/json", httpMethod = "POST")
    @PostMapping("/homePage")
    public ResultInfo<DashBoardRes> getDashBoard(){
        return ResultInfo.success(opService.getHomeDashBoard());
    }

    @ApiOperation(value = "客户列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/getByPage")
    public ResultInfo<Pagination<CustomerListRes>> getCustomerByPage(@RequestBody @Validated CustomerListReq req){
        return ResultInfo.success(opService.getCustomerByPage(req));
    }

    @ApiOperation(value = "客户详情", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/getDetail")
    public ResultInfo<CustomerDetailRes> getDetail(@RequestBody @Validated CustomerDetailReq req){
        return ResultInfo.success(opService.getCustomerDetail(req));
    }

    @ApiOperation(value = "添加客户", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/add")
    public ResultInfo<Boolean> addCustomer(@RequestBody @Validated AddCustomerReq req){
        return ResultInfo.success(opService.addCustomer(req));
    }

    @ApiOperation(value = "中心列表查询", produces = "application/json", httpMethod = "POST")
    @PostMapping("/center/getByPage")
    public ResultInfo<Pagination<CenterListRes>> getCenterListByPage(@RequestBody @Validated OpCenterListReq req){
        return ResultInfo.success(opService.getCenterByPage(req));
    }

    @ApiOperation(value = "重置客户管理员密码", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/resetPwd")
    public ResultInfo<Boolean> resetPwd(@RequestBody @Validated ResetPasswordReq req){
        return ResultInfo.success(opService.resetCustomerPwd(req));
    }

    @ApiOperation(value = "修改客户", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/edit")
    public ResultInfo<Boolean> editCustomer(@RequestBody @Validated EditCustomerReq req){
        return ResultInfo.success(opService.editCustomer(req));
    }

    @ApiOperation(value = "查看项目列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/project/getByPage")
    public ResultInfo<Pagination<ProjectListRes>> getProjectByPage(@RequestBody @Validated ProjectListReq req){
        return ResultInfo.success(opService.getProjectList(req));
    }

    @ApiOperation(value = "查看项目详情", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/project/getDetail")
    public ResultInfo<ProjectDetailRes> getProjectDetail(@RequestBody @Validated ProjectDetailReq req){
        return ResultInfo.success(opService.getProjectDetail(req));
    }

    @ApiOperation(value = "受试者列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/subjects/getByPage")
    public ResultInfo<Pagination<SubjectsUserInfoListRes>> getSubjectList(@RequestBody @Validated SubjectsUserInfoListReq req){
        return ResultInfo.success(opService.getSubjectList(req));
    }

    @ApiOperation(value = "受试者详情", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/subjects/getDetail")
    public ResultInfo<SubjectDetailRes> getSubjectDetail(@RequestBody @Validated SubjectDetailReq req){
        return ResultInfo.success(opService.getSubjectDetail(req));
    }

    @ApiOperation(value = "受试者参与项目列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/subjects/getProjects")
    public ResultInfo<Pagination<ProjectListRes>> getProjects(@RequestBody @Validated SubjectDetailReq req){
        return ResultInfo.success(opService.getProjectList4Subject(req));
    }

    @ApiOperation(value = "结算单列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/settle/getByPage")
    public ResultInfo<SettlePageRes> getSettleByPage(@RequestBody @Validated OpSettleListReq req){
        return ResultInfo.success(opService.getSettleByPage(req));
    }

    @ApiOperation(value = "结算单详情", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/settle/getDetail")
    public ResultInfo<SettleDetail4OpRes> getSettleDetail(@RequestBody @Validated SettleDetailReq req){
        return ResultInfo.success(opService.getSettleDetail(req));
    }

    @ApiOperation(value = "结算单付款成功", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/settle/paySuccess")
    public ResultInfo<Boolean> paySuccess(@RequestBody @Validated SettleDetailReq req){
        return ResultInfo.success(opService.paySuccess(req));
    }

    @ApiOperation(value = "结算单批量付款成功", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/settle/batchPaySuccess")
    public ResultInfo<Boolean> batchPaySuccess(@RequestBody @Validated SettleBatchPaySuccessReq req){
        return ResultInfo.success(opService.batchPaySuccess(req));
    }


    @ApiOperation(value = "结算单付款失败", produces = "application/json", httpMethod = "POST")
    @PostMapping("/customer/settle/payFail")
    public ResultInfo<Boolean> payFailed(@RequestBody @Validated SettleRejectReq req){
        return ResultInfo.success(opService.payFailed(req));
    }

    @ApiOperation(value = "用户列表", produces = "application/json", httpMethod = "POST")
    @PostMapping("/user/getByPage")
    public ResultInfo<Pagination<OpUserListRes>> getUserByPage(@RequestBody @Validated PageBaseVO req){
        return ResultInfo.success(opService.getOpUserList(req));
    }

    @ApiOperation(value = "运营端人员重置密码", produces = "application/json", httpMethod = "POST")
    @PostMapping("/user/resetPwd")
    public ResultInfo<Boolean> resetOpUserPwd(@RequestBody @Validated ResetPasswordReq req){
        return ResultInfo.success(opService.resetOpUserPwd(req));
    }

    @ApiOperation(value = "运营端人员启用/禁用", produces = "application/json", httpMethod = "POST")
    @PostMapping("/user/toggle")
    public ResultInfo<Boolean> enableOrDisable(@RequestBody @Validated ToggleOpUserReq req){
        return ResultInfo.success(opService.enableOrDisable(req));
    }

    @ApiOperation(value = "添加运营端人员", produces = "application/json", httpMethod = "POST")
    @PostMapping("/user/add")
    public ResultInfo<AddUserRes> addOpUserPwd(@RequestBody @Validated AddOpUserReq req){
        return ResultInfo.success(opService.addOpUserPwd(req));
    }

    @ApiOperation(value = "导出结算单", produces = "application/json", httpMethod = "POST")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "payType",value = "付款类型",dataType = "String",required = false),
            @ApiImplicitParam(name = "status",value = "结算单状态",dataType = "String",required = false),
            @ApiImplicitParam(name = "pkProject",value = "项目主键",dataType = "Long",required = false),
            @ApiImplicitParam(name = "pkCenter",value = "中心主键",dataType = "Long",required = false),
            @ApiImplicitParam(name = "pkSubjects",value = "受试者用户（人）主键",dataType = "String",required = false),
            @ApiImplicitParam(name = "subjectsAlias",value = "受试者简称",dataType = "String",required = false),
            @ApiImplicitParam(name = "pkCustomer",value = "客户主键",dataType = "String",required = false),
            @ApiImplicitParam(name = "fullData",value = "是否导出全量数据1:是；0：否",dataType = "String",required = false),
            @ApiImplicitParam(name = "authorization",value = "token",dataType = "String",required = true)
    })
    @PostMapping("/settle/export")
//    @GetMapping("/settle/export")
    public void exportSettle(@RequestParam(name = "payType", required = false) String payType,
                             @RequestParam(name = "status", required = false) String status,
                             @RequestParam(name = "pkProject", required = false) Long pkProject,
                             @RequestParam(name = "pkCenter", required = false) Long pkCenter,
                             @RequestParam(name = "pkSubjects", required = false) String pkSubjects,
                             @RequestParam(name = "subjectsAlias", required = false) String subjectsAlias,
                             @RequestParam(name = "pkCustomer", required = false) Long pkCustomer,
                             @RequestParam(name = "authorization", required = false) String authorization,
                             @RequestParam(name = "fullData", required = false) String fullData,
                             HttpServletResponse response){
        OpSettleListReq req = new OpSettleListReq();
        req.setPayType(payType);
        req.setStatus(status);
        req.setPkProject(pkProject);
        req.setPkCenter(pkCenter);
        req.setPkSubjects(pkSubjects);
        req.setSubjectsAlias(subjectsAlias);
        req.setPkCustomer(pkCustomer);
        req.setAuthorization(authorization);
        req.setFullData(fullData);
        opService.exportSettle(req,response);
    }
}
